<?php

namespace Mlym\CodeGeneration\ControllerGeneration\Method;

class GetByWhere extends MethodAbstract
{

    protected $methodName = 'getByWhere';
    protected $methodDescription = '自定义条件获取数据';
    protected $methodAllow = 'GET';

    function addMethodBody()
    {
        $modelName = $this->getModelName();

        $methodBody = <<<Body
\$where = \$this->request()->getQueryParams();
\$model = new {$modelName}();
if (empty(\$where)){
    \$this->writeJson(Status::CODE_BAD_REQUEST, [], '缺少条件');
}else {
    \$info = \$model->get(\$where);
    if (\$info) {
        \$this->writeJson(Status::CODE_OK, \$info, "操作成功");
    } else {
        \$this->writeJson(Status::CODE_OK, [], '数据不存在');
    }
}

Body;
        $this->method->setBody($methodBody);

    }


    function addComment()
    {
        $this->method->addComment("@throws \Throwable");
    }
}
